#ifndef LOG_COLLECTION_UTILS_HPP
#define LOG_COLLECTION_UTILS_HPP

#include <string>

namespace LogCollector
{

static constexpr int SD_LOG_DEBUG { 7 };
static constexpr int SD_LOG_INFO { 6 };
static constexpr int SD_LOG_NOTICE { 5 };
static constexpr int SD_LOG_WARNING { 4 };
static constexpr int SD_LOG_ERROR { 3 };
static constexpr int SD_LOG_CRITICAL { 2 };

//! 定义返回状态码
enum class ReturnStatus {
    SUCCESS = 0,
    NOT_INIT,
    ALREADY_INIT,
    INVALID_PARAM,
    FILE_ERROR,
    BUS_ERROR,
    NOT_PROCESS_FROM_JOURNAL,
    UNKNOWN_ERROR
};

//! 定义日志级别
struct Severity{
    enum class Level : uint8_t {
        DEBUG,
        INFO,
        WARNING,
        ERROR,
        CRITICAL,
        SERVICE_LEVEL_SIZE
    };

    static constexpr int toJournalLevel(Level level) {
        switch (level) {
            case Severity::Level::DEBUG:
                return SD_LOG_DEBUG;
            case Severity::Level::INFO:
                return SD_LOG_INFO;
            case Severity::Level::WARNING:
                return SD_LOG_WARNING;
            case Severity::Level::ERROR:
                return SD_LOG_ERROR;
            case Severity::Level::CRITICAL:
                return SD_LOG_CRITICAL;
            default:
                return SD_LOG_DEBUG;
        }
    }

    static constexpr Level fromJournalLevel(int journalLevel) {
        switch (journalLevel) {
            case SD_LOG_DEBUG:
                return Severity::Level::DEBUG;
            case SD_LOG_INFO:
            case SD_LOG_NOTICE:
                return Severity::Level::INFO;
            case SD_LOG_WARNING:
                return Severity::Level::WARNING;
            case SD_LOG_ERROR:
                return Severity::Level::ERROR;
            case SD_LOG_CRITICAL:
            default:
                return Severity::Level::CRITICAL;
        }
    }

    static Level fromConfigString(const std::string& levelStr) {
        if (levelStr == "DEBUG") {
            return Severity::Level::DEBUG;
        } else if (levelStr == "INFO") {
            return Severity::Level::INFO;
        } else if (levelStr == "WARNING") {
            return Severity::Level::WARNING;
        } else if (levelStr == "ERROR") {
            return Severity::Level::ERROR;
        } else if (levelStr == "CRITICAL") {
            return Severity::Level::CRITICAL;
        }

        return Severity::Level::DEBUG;
    }

};

}

#endif // LOG_COLLECTION_UTILS_HPP